<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="/css/styletable.css" type="text/css"/>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/layui.all.js" charset="utf-8"></script>
    <script src="/js/jquery.2.1.4.js" charset="utf-8"></script>
</head>
<body>
<script>
    $(function () {
        $("#checkAll").bind("click",function(){
            $(".check").prop("checked",this.checked);
        });
    });
    function stop() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#userform").attr("action", "/user/stop").submit();
        }
    }

    function start() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#userform").attr("action", "/user/start").submit();
        }
    }

    function edit() {
        if ($(".check:checked").size() != 1) {
            layer.alert('请选择一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#userform").attr("action", "/user/toedit").submit();
        }
    }

    function dele() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            $("#userform").attr("action", "/user/del").submit();
        }
    }

    function rese() {
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            /*layer.alert('密码重置成功', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            }, function () {
                $("#userform").attr("action", "/user/rese").submit();
            });*/
            $("#userform").attr("action", "/user/rese").submit();
        }
    }

    function batch() {
        layer.prompt({
            formType: 0,
            value: '',
            title: '请输入学籍(批量删除)',
            area: ['200px', '30px']
        }, function (value, index, elem) {
            if (value != "") {
                window.location.href = "/user/batch/" + value;
                layer.close(index);
            }
        });
    }

    function role() {
        var message = '<label for="sel">选择角色：</label>\n' +
            '<select id="sel" name="selval" style="width: 150px;height: 25px">\n' +
            '<c:forEach items="${rolename}" var="rname">\n' +
            '\t<option>${rname}</option>\n' +
            '</c:forEach>\n' +
            '</select>';
        if ($(".check:checked").size() == 0) {
            layer.alert('请至少选一项', {
                skin: 'layui-layer-molv'
                , closeBtn: 0
            });
        } else {
            layer.open({
                title: '分配角色'
                , content: message
                , yes: function (index, layero) {
                    $("#userform").attr("action", "/user/editRole/"+$("#sel  option:selected").text()).submit();
                    layer.close(index); //如果设定了yes回调，需进行手工关闭
                }
            });
        }
    }
</script>
<div style="margin: 10px 15px 0px 15px">
    <div style="margin-top: 1px;margin-left: 1px;margin-bottom: 10px">
        <button class="layui-btn" onclick="start();">启用</button>
        <button class="layui-btn layui-btn-danger" onclick="stop();">禁用</button>
        <a class="layui-btn layui-btn-normal" href="/user/toadd">添加</a>
        <button class="layui-btn layui-btn-edit" onclick="edit();">编辑</button>
        <button class="layui-btn layui-btn-warm" onclick="dele();">删除</button>
        <button class="layui-btn layui-btn-role" onclick="role();">分配角色</button>
        <button class="layui-btn layui-btn-delete" onclick="batch();">批量删除</button>
        <button class="layui-btn layui-btn-primary" onclick="rese();">重置密码</button>

    </div>
    <form id="userform" method="post">
        <table style="width: 100%">
            <tr>
                <th width="5%"><input type="checkbox" id="checkAll"></th>
                <th width="15%">用户名</th>
                <th width="15%">联系电话</th>
                <th width="15%">真实姓名</th>
                <th width="15%">拥有角色</th>
                <th width="10%">学 籍</th>
                <th width="15%">注册时间</th>
                <th width="10%">状态</th>
            </tr>

            <c:forEach items="${users}" var="user">
                <tr>
                    <td align="center"><input class="check" name="checks" value="${user.uid}" type="checkbox"/></td>
                    <td>${user.username}</td>
                    <td>${user.phone}</td>
                    <td>${user.truename}</td>
                    <td>${user.role}</td>
                    <td>${user.study}</td>
                    <td>${user.date}</td>
                    <td align="center"><span
                            class="layui-btn layui-btn-mini <c:if test="${user.state=='禁用'}">layui-btn-danger</c:if>">${user.state}</span>
                    </td>
                </tr>
            </c:forEach>
        </table>
    </form>
</div>
</body>
</html>
